package org.jeecg.modules.system.upgrade.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.param.pile.entity.BikePile;
import org.jeecg.modules.param.station.entity.BikeStation;
import org.jeecg.modules.system.upgrade.entity.BikeUpgradeApp;
import org.jeecg.modules.system.upgrade.mapper.BikeUpgradeAppMapper;
import org.jeecg.modules.system.upgrade.service.IBikeUpgradeAppService;
import org.jeecg.modules.utils.QRCodeUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
 * @Description: APP类型表(应用程序)
 * @Author: 月月鸟
 * @Date:   2021-07-14
 * @Version: V1.0
 */
@Service
public class BikeUpgradeAppServiceImpl extends ServiceImpl<BikeUpgradeAppMapper, BikeUpgradeApp> implements IBikeUpgradeAppService {

    //@Value("${application.admin}")
    private String domain;
    @Resource
    private BikeUpgradeAppMapper bikeUpgradeAppMapper;


    @Override
    public void getCode( HttpServletResponse response) throws IOException {
        //以流的形式输出到前端
//---------------------------------------------------------------------------

        // 设置响应流信息
        response.setContentType("image/jpg");
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        ServletOutputStream outputStream = response.getOutputStream();
        ////获取一个二维码图片
        //BitMatrix code = QRCodeUtils.createCode(OrCode + "?code=" + bikeStation.getCode() + bikePile.getCode() + bikePile.getCheckCode());
        //MatrixToImageWriter.writeToStream(code, "jpg", outputStream);
        //获取一个二维码图片
        BufferedImage bufferedImage = null;
        try {
            bufferedImage = QRCodeUtils.createImage(domain+"/bike/scan/","软件下载二维码");
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ImageIO.write(bufferedImage, "jpg", bos);
            response.getOutputStream().write(bos.toByteArray());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }



}
